home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / GIMP 2.6.8 / gimp-2.6.8-i686-setup.exe / {app} / share / gimp / 2.0 / scripts / select-to-brush.scm < prev    next >
Text File  |  2009-12-15  |  5KB  |  145 lines

  1. ; GIMP - The GNU Image Manipulation Program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; Selection-to-brush
  5. ; Copyright (c) 1997 Adrian Likins
  6. ; aklikins@eos.ncsu.edu
  7. ;
  8. ; Takes the current selection, saves it as a brush, and makes it the
  9. ; active brush..
  10. ;
  11. ;       Parts of this script from Sven Neuman's Drop-Shadow and
  12. ;       Seth Burgess's mkbrush scripts.
  13. ;
  14. ; This program is free software; you can redistribute it and/or modify
  15. ; it under the terms of the GNU General Public License as published by
  16. ; the Free Software Foundation; either version 2 of the License, or
  17. ; (at your option) any later version.
  18. ;
  19. ; This program is distributed in the hope that it will be useful,
  20. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22. ; GNU General Public License for more details.
  23. ;
  24. ; You should have received a copy of the GNU General Public License
  25. ; along with this program; if not, write to the Free Software
  26. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27.  
  28.  
  29. (define (script-fu-selection-to-brush image
  30.                                       drawable
  31.                                       name
  32.                                       filename
  33.                                       spacing)
  34.   (let* (
  35.         (type (car (gimp-drawable-type-with-alpha drawable)))
  36.         (selection-bounds (gimp-selection-bounds image))
  37.         (select-offset-x  (cadr selection-bounds))
  38.         (select-offset-y  (caddr selection-bounds))
  39.         (selection-width  (- (cadr (cddr selection-bounds))  select-offset-x))
  40.         (selection-height (- (caddr (cddr selection-bounds)) select-offset-y))
  41.         (from-selection 0)
  42.         (active-selection 0)
  43.         (brush-draw-type 0)
  44.         (brush-image-type 0)
  45.         (brush-image 0)
  46.         (brush-draw 0)
  47.         (filename2 0)
  48.         )
  49.  
  50.     (gimp-context-push)
  51.  
  52.     (gimp-image-undo-disable image)
  53.  
  54.     (if (= (car (gimp-selection-is-empty image)) TRUE)
  55.         (begin
  56.           (gimp-selection-layer-alpha drawable)
  57.           (set! from-selection FALSE)
  58.         )
  59.         (begin
  60.           (set! from-selection TRUE)
  61.           (set! active-selection (car (gimp-selection-save image)))
  62.         )
  63.     )
  64.  
  65.     (gimp-edit-copy drawable)
  66.  
  67.     (set! brush-draw-type
  68.           (if (= type GRAYA-IMAGE)
  69.               GRAY-IMAGE
  70.               RGBA-IMAGE))
  71.  
  72.     (set! brush-image-type
  73.           (if (= type GRAYA-IMAGE)
  74.               GRAY
  75.               RGB))
  76.  
  77.     (set! brush-image (car (gimp-image-new selection-width
  78.                                            selection-height
  79.                                            brush-image-type)))
  80.  
  81.     (set! brush-draw
  82.           (car (gimp-layer-new brush-image
  83.                                selection-width
  84.                                selection-height
  85.                                brush-draw-type
  86.                                "Brush"
  87.                                100
  88.                                NORMAL-MODE)))
  89.  
  90.     (gimp-image-add-layer brush-image brush-draw 0)
  91.  
  92.     (gimp-selection-none brush-image)
  93.  
  94.     (if (= type GRAYA-IMAGE)
  95.         (begin
  96.           (gimp-context-set-background '(255 255 255))
  97.           (gimp-drawable-fill brush-draw BACKGROUND-FILL))
  98.         (gimp-drawable-fill brush-draw TRANSPARENT-FILL)
  99.     )
  100.  
  101.     (let ((floating-sel (car (gimp-edit-paste brush-draw FALSE))))
  102.       (gimp-floating-sel-anchor floating-sel)
  103.     )
  104.  
  105.     (set! filename2 (string-append gimp-directory
  106.                                    "/brushes/"
  107.                                    filename
  108.                                    (number->string image)
  109.                                    ".gbr"))
  110.  
  111.     (file-gbr-save 1 brush-image brush-draw filename2 "" spacing name)
  112.  
  113.     (if (= from-selection TRUE)
  114.         (begin
  115.           (gimp-selection-load active-selection)
  116.           (gimp-image-remove-channel image active-selection)
  117.         )
  118.     )
  119.  
  120.     (gimp-image-undo-enable image)
  121.     (gimp-image-set-active-layer image drawable)
  122.     (gimp-image-delete brush-image)
  123.     (gimp-displays-flush)
  124.  
  125.     (gimp-context-pop)
  126.  
  127.     (gimp-brushes-refresh)
  128.     (gimp-context-set-brush name)
  129.   )
  130. )
  131.  
  132. (script-fu-register "script-fu-selection-to-brush"
  133.   _"To _Brush..."
  134.   _"Convert a selection to a brush"
  135.   "Adrian Likins <adrian@gimp.org>"
  136.   "Adrian Likins"
  137.   "10/07/97"
  138.   "RGB* GRAY*"
  139.   SF-IMAGE       "Image"       0
  140.   SF-DRAWABLE    "Drawable"    0
  141.   SF-STRING     _"Brush name"  "My Brush"
  142.   SF-STRING     _"File name"   "mybrush"
  143.   SF-ADJUSTMENT _"Spacing"     '(25 0 1000 1 1 1 0)
  144. )
  145.